package com.pks.autoInsurance.dao;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public abstract class AutoInsuranceDAO {

	static {
		try {
			Class.forName("oracle.jdbc.OracleDriver");

		} catch (ClassNotFoundException e) {
			System.out.println(e.getMessage());
		}
	}

	// private static final String URL =
	// "jdbc:oracle:thin:@10.227.39.240:1521:oracle";
	// private static final String USER = "ferrari";
	// private static final String PASSWORD = "maruti";

	public Connection getConnection() {
		System.out.println(getClass() + "::::getConnection::::begin");
		/*
		 * try { return DriverManager.getConnection(URL, USER, PASSWORD); }
		 * catch (SQLException e) { return null; }
		 */
		Connection connection = null;
		DataSource ds = null;
		try {
			Context initContext = new InitialContext();
			Context envContext = (Context) initContext.lookup("java:/comp/env");
			ds = (DataSource) envContext.lookup("jdbc/oracledb");
			connection = ds.getConnection();
		} catch (NamingException e) {
			System.err.println(getClass() + "::::" + e.getMessage());
		} catch (SQLException e) {
			System.err.println(getClass() + "::::" + e.getMessage());
		}
		System.out.println(getClass() + "::::getConnection::::end");
		return connection;
	}
}
